package com.ogawa.jopai.devicemanage.activity

import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.ogawa.base.base.BaseVMActivity
import com.ogawa.jopai.devicemanage.bean.DeviceShareRequest
import com.ogawa.jopai.devicemanage.viewmodel.DeviceManageViewModel
import com.ogawa.projectcommon.constants.UrlPathConstant
import com.ogawa.joypal.devicemanage.R
import kotlinx.android.synthetic.main.activity_add_share_device.*


@Route(path = UrlPathConstant.ACTIVITY_SHARE_DEVICE)
public class AddShareDeviceActivity : BaseVMActivity<DeviceManageViewModel>() {

    @JvmField
    @Autowired(name = "sn")
    var sn = ""
    override fun getLayoutId(): Int {
        return R.layout.activity_add_share_device
    }

    override fun initView() {
        super.initView()
        ARouter.getInstance().inject(this)
        setTitle(getString(R.string.share_title))
        nextBt.setOnClickListener {
            var inputStr = inputAccountEt.text.toString()
            if (inputStr.isBlank()){
                ToastUtils.showShort(getString(R.string.share_no_input_emial_phone))
                return@setOnClickListener
            }
            if (sn.isBlank()){
                ToastUtils.showShort(getString(R.string.choose_device))
                return@setOnClickListener
            }
            var mDeviceShareRequest = DeviceShareRequest()
            mDeviceShareRequest.sn = sn
            mDeviceShareRequest.userName = inputStr
            mViewModel.deviceShare(mDeviceShareRequest)
        }

    }

    override fun providerVMClass(): Class<DeviceManageViewModel>? {
        return DeviceManageViewModel::class.java
    }

    override fun observeVM() {
        mViewModel.mDeviceShareResponse.observe(this, Observer {
            ToastUtils.showShort(getString(R.string.share_success))
            finish()
        })
    }
}